
// http://193.112.55.79:9090/api/getgsproduct
$(function(){
  // 查询
  getgsproduct();
  function getgsproduct(shopid, areaid){
    // console.log(shopid, areaid)
    // "shopid":0, "shopName":"京东"; 
    // "areaid":0,"areaName":"华北（北京、山西等）
    var shopid = shopid || 0;
    var areaid = areaid || 0;
    var data = "?shopid="+shopid+"&areaid="+areaid;
    $.ajax({
      type: "get",
      url: "http://193.112.55.79:9090/api/getgsproduct",
      data: data,
      dataType: "json",
      success: function (res) {
        // console.log(res)
        var htmlStr = template('gsproductTmp', res);
        $('.gsproduct_list').html(htmlStr);
      }
    });
  }

  // 获取shop
  $.ajax({
    type: "get",
    url: "http://193.112.55.79:9090/api/getgsshop",
    dataType: "json",
    success: function (res) {
      console.log(res)
      $.each(res.result, function (idx, val) { 
        $('#from').append('<option value="'+val.shopId+'">'+val.shopName+'</option>')
      });
    }
  });

  // 获取area
  $.ajax({
    type: "get",
    url: "http://193.112.55.79:9090/api/getgsshoparea",
    dataType: "json",
    success: function (res) {
      console.log(res)
      $.each(res.result, function (idx, val) { 
        $('#area').append('<option value="'+val.areaId+'">'+val.areaName+'</option>')
      });
    }
  });
  

  // 查询条件
  var fromId, areaId;
  $('#from').on('change', function(){
    // 获取id
    fromId = $('#from').val();
    // 查询
    getgsproduct(fromId, areaId);
  })
  $('#area').on('change', function(){
    // 获取id
    areaId = $('#area').val();
    // 查询
    getgsproduct(fromId, areaId);
  })


})